from datetime import datetime

from sanic.views import HTTPMethodView


class BaseAsyncListCreateApi(HTTPMethodView):
    async def get(self, request):
        return await self.list(request)

    async def list(self, request):
        pass

    async def post(self, request):
        return await self.create(request)

    async def create(self, request):
        pass


class BaseAsyncRetrieveUpdateDestroyApi(HTTPMethodView):

    update_at = True

    async def get(self, request, pk):
        return await self.retrieve(request, pk)

    async def retrieve(self, request, pk):
        pass

    async def put(self, request, pk):
        if self.update_at:
            request.json['update_at'] = datetime.now()
        return await self.update(request, pk)

    async def update(self, request, pk):
        pass

    async def delete(self, request, pk):
        return await self.destroy(request, pk)

    async def destroy(self, request, pk):
        pass
